import { TOKEN_KEY, USERINFO_KEY } from '@/constants'
import type { FormDataType } from '@/types/user'
import Cookies from 'js-cookie'
// 获取token
export const getToken = () => {
  return Cookies.get(TOKEN_KEY)
}
// 设置token
export const setCoToken = (token: string) => {
  Cookies.set(TOKEN_KEY, token)
}
// 删除token
export const removeCoToken = () => {
  Cookies.remove(TOKEN_KEY)
}

// 获取userinfo
export const getCoUserInfo = () => {
  if (!Cookies.get(USERINFO_KEY)) return
  return JSON.parse(Cookies.get(USERINFO_KEY)!)
}
// 设置userinfo
export const setCoUserInfo = (userInfo: FormDataType) => {
  Cookies.set(USERINFO_KEY, JSON.stringify(userInfo))
}
// 删除userinfo
export const removeCoUserInfo = () => {
  Cookies.remove(USERINFO_KEY)
}
